#define _CRT_SECURE_NO_WARNINGS   1

#include<iostream>
#include<algorithm>

using namespace std;

int n,a[111111];          
int ans = 0;               

int main()
{
	cin >> n;
	for (int i = 1; i <=n; i++)
	{
		cin >> a[i];
	}
	if (n == 1)            
	{
		cout << a[1] << endl;
		cout << a[1] << endl;
	}
	int nn = n;
	sort(a + 1, a + n + 1);
	while (n > 3)
	{
		if (a[1] + a[n - 1] < 2 * a[2])
		{
			ans += a[n] + a[1] * 2 + a[n - 1];
		}
		else
		{
			ans += a[2] + a[1] + a[2] + a[n];
		}
		n -= 2;
	}
	if (n == 2)
	{
		ans += a[2];
	}
	else
	{
		ans += a[1] + a[2] + a[3];
	}
	cout << ans << endl;
	n = nn;
	while (n > 3)
	{
		if (a[1] + a[n - 1] < 2 * a[2])
		{
			cout << a[1] << "  " << a[n]
				<< endl << a[1] << endl << a[1] 
				<< "  " << a[n - 1] << endl << a[1] << endl;
		}
		else
		{
			cout << a[1] << "  " << a[2]
				<< endl << a[1] << endl << a[n - 1] 
				<< "  " << a[n] << endl << a[2] << endl;
		}
		n -= 2;
	}
	if (n == 2)
	{
		cout << a[1] << "  " << a[2] << endl;
	}
	else
	{
		cout << a[1] << "  " << a[3] << endl << a[1] << endl << a[1] << "  " << a[2];
	}
	return 0;
}